package org.example.java.io;

import java.io.*;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class CopyFile {
  public static void main(String[] args) throws Exception {
    String infile = "data" + File.separator + "dictionary.txt";
    String outfile = "data" + File.separator + "copy.txt";
    File file = new File(outfile);
    if (file.exists() && file.delete()) {
      System.out.println("copy file delete success.");
    }
    long start = System.currentTimeMillis();
    // 获取源文件和目标文件的输入输出流

    try (BufferedReader reader = new BufferedReader(new FileReader(infile));
         BufferedWriter writer = new BufferedWriter(new FileWriter(outfile))) {
      String line = null;
      int i = 1;
      while ((line = reader.readLine()) != null) {
        writer.write(line + " " + i++);
        writer.newLine();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    System.out.println("Spend: " + (System.currentTimeMillis() - start) + "ms");
  }
}